package com.geek.bucks.controller

import com.geek.bucks.entity.Coffee
import com.geek.bucks.service.CoffeeService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.MediaType
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("/coffee")
class CoffeeController(@Autowired private val coffeeService: CoffeeService) {

    @GetMapping("")
    fun getAll(): List<Coffee>? = coffeeService.allCoffee

    @GetMapping("", params = ["name"])
    fun getByName(@RequestParam name: String): List<Coffee>? = coffeeService.getCoffee(name)

    @GetMapping("/{id}", produces = [MediaType.APPLICATION_JSON_UTF8_VALUE])
    fun getById(@PathVariable id: Long): Coffee? = coffeeService.getCoffee(id)
}
